//
//  BWFTabBarController.swift
//  网易新闻项目
//
//  Created by 薄文飞 on 16/3/2.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class BWFTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let b = BWFTabBar()
        
        b.callBack = { [weak self] in
        
            print("哈哈哈\(self)")
        }
        //该类的对象指向BWFBar
        setValue(b, forKey: "tabBar")

        //调用方法
        addChildViewController(BWFHomeViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(BWFMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(BWFDiscorverViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(BWFMineViewController(), imageName: "tabbar_profile", title: "我")

    }

    private func addChildViewController(childController: UIViewController , imageName: String , title: String) {
        
        //把导航控制器和标签控制器都添加文字
//        childController.navigationItem.title = title
//        childController.tabBarItem.title = title
        childController.title = title
        
        //给标签添加图片。并设置不渲染
        childController.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(.AlwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置选中状态下字体的颜色，不能直接赋值，需要先定义再赋值
        let highlightTitelColoor = [NSForegroundColorAttributeName : UIColor.redColor()]
        childController.tabBarItem.setTitleTextAttributes(highlightTitelColoor, forState: .Selected)
        
        //设置选中状态下的字体的大小
//        let highlightTitelFront = [NSFontAttributeName : UIFont.systemFontOfSize(17)]
//        childController.tabBarItem.setTitleTextAttributes(highlightTitelFront, forState: .Highlighted)
        
        addChildViewController(BWFNavigationController(rootViewController: childController))
    }

}
